#include<stdio.h>
#define DEBUG
#ifdef DEBUG
#include<conio.h>
#endif
typedef struct people{
    long index;
    people *next;
};
long n,m;
people *list;
void input(){
    FILE *fp=fopen("Josephus.INP","r");
    fscanf(fp,"%ld%ld",&n,&m);
    fclose(fp);
}
void init(){
    people *next;
    list=new people;
    (*list).index=1;
    (*list).next=NULL;
    next=list;
    for(long i=2;i<=n;i++){
        people *p=new people;
        (*p).index=i;
        (*p).next=NULL;
        (*next).next=p;
        next=p;
    }
    (*next).next=list;
}
#ifdef DEBUG
void out(){
    people *a=list;
    for(long i=1;i<=n;i++){
        printf("%ld\t",(*a).index);
        a=(*a).next;
    }
    getch();
}
#endif
void output(){
    FILE *fp=fopen("Josephus.out","w");
    long i,j;
    for(i=1;i<=n;i++){
        for(j=1;j<(m-1)%n;j++)list=(*list).next;
        if(i>1)fprintf(fp," ");
        fprintf(fp,"%ld",(*((*list).next)).index);
        (*list).next=(*((*list).next)).next;
        list=(*list).next;
    }
    fclose(fp);
}
int main(){
    input();
    init();
    output();
    return 0;
}


